package com.mall.util;

import java.math.BigDecimal;

public class StringUtil
{
	public static Integer toInteger(String i)
	{
		Integer integer = null;
		try
		{
			integer = new Integer(i);
		}
		catch (Exception e)
		{
			// TODO: handle exception
		}
		
		return integer;
	}
	
	public static BigDecimal toBigDecimal(String b)
	{
		BigDecimal bigDecimal = null;
		try
		{
			bigDecimal = new BigDecimal(b);
		}
		catch (Exception e)
		{
			// TODO: handle exception
		}
		
		return bigDecimal;
	}
	
	public static Boolean toBoolean(String str)
	{
		Boolean bool = null;
		try
		{
			bool = new Boolean(str);
		}
		catch (Exception e)
		{
			// TODO: handle exception
		}
		
		return bool;
	}
	
	public static String filterNull(String s)
	{
		
		if(s==null || s.trim().length() == 0)
		{
			s = null;
		}
		
		return s;
	}
	
	/**
	 * 如果字符串为null,则返回空字符串""
	 * */
	public static String null2Empty(String s)
	{
		if(s == null)
		{
			return "";
		}
		else 
		{
			return s;
		}
	}
	
	/**
	 * 如果字符串为null,则返回默认字符串defaultValue
	 * */
	public static String null2Empty(String s,String defaultValue)
	{
		if(s == null)
		{
			return defaultValue;
		}
		else 
		{
			return s;
		}
	}
	
	public static String integerToString(Integer i)
	{
		if(i == null)
		{
			return "";
		}
		return i.toString();
	}
	
	public static String doubleToString(BigDecimal i){
		if(i == null){
			return "";
		}
		
		return i.toString();
	}
	
	
	public static String bigDecimalToString(BigDecimal i){
		if(i == null){
			return "";
		}
		
		return i.toString();
	}
	
	public static String empty2null(String str)
	{
		if(str!=null && str.trim().length() == 0)
		{
			return null;
		}
		return str;
	}
	
}
